﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.IO;

namespace RN.ERP.Web.Enterprise
{
    public partial class UploadFileShowListForCpp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                hdnObjectGuid.Value = Request.QueryString["filename"];
                if (Request.QueryString["fileType"] != null)
                {
                    hdnFileType.Value = Request.QueryString["fileType"];
                }
                if (Request.QueryString["SysCode"] != null)
                {
                    hdnSysCode.Value = Request.QueryString["SysCode"];
                }
                if (Request.QueryString["FuncCode"] != null)
                {
                    hdnFuncCode.Value = Request.QueryString["FuncCode"];
                }
                if (!string.IsNullOrEmpty(Request.QueryString["title"]) && Request.QueryString["title"] != "")
                {
                    lblTitle.Text = Request.QueryString["title"];
                    if (lblTitle.Text.IndexOf("扫描件") < 0)
                    {
                        lblTitle.Text = "查看"+lblTitle.Text + "扫描件";
                    }
                }
                BindFiles();
            }
        }

        private void BindFiles()
        {
            string objectGuid = hdnObjectGuid.Value.Trim();
            string sysCode = hdnSysCode.Value.Trim();
            string funcCode = hdnFuncCode.Value.Trim();
            if ((!string.IsNullOrEmpty(objectGuid)) && (!string.IsNullOrEmpty(sysCode)) && (!string.IsNullOrEmpty(funcCode)))
            {
                using (FileService.FileWebServiceSoapClient client = new FileService.FileWebServiceSoapClient())
                {
                    FileService.ArrayOfString files = client.GetFileList(objectGuid, sysCode, funcCode);
                    rptImgs.DataSource = files;
                    rptImgs.DataBind();
                }
            }
        }

        public string GetImgUrl(object fileName)
        {
            string sysCode = hdnSysCode.Value.Trim();
            string funcCode = hdnFuncCode.Value.Trim();
            return string.Format("../Handlers/GetFileHandler.ashx?fileName={0}&sysCode={1}&funcCode={2}&rand ={3}", fileName, sysCode, funcCode, Guid.NewGuid());
        }

        public string OpenNewPageShowFile(object fileName)
        {
            string sysCode = hdnSysCode.Value.Trim();
            string funcCode = hdnFuncCode.Value.Trim();
            return string.Format("UploadFileShowNewpage.aspx?fileName={0}&sysCode={1}&funcCode={2}&rand ={3}", fileName, sysCode, funcCode, Guid.NewGuid());
        }
    }
}